<?php
/**
 * Created by PhpStorm.
 * User: 86182
 * Date: 2020/6/26
 * Time: 13:31
 */

namespace App\Serves;
use App\Models\Goods\GoodsSku;
use App\Models\User;
use App\Utils\Token;
use App\Models\Goods\Goods as GoodsModel;
use App\Models\Goods\GoodsSku as GoodsSkuModel;
use App\Models\Goods\Speci as SpeciModel;
use App\Models\Goods\SpeciValue as SpeciValueModel;

class GoodsSkuServe
{

    public static function getGoodsSkuBySkuSpeciValueId($speci_value_ids,$id){
        $goods_skus = GoodsSku::getGoodsSkuBySkuSpeciValueId($speci_value_ids,$id);
        return $goods_skus ;
    }

    public static function getGoodsAndGoodsSkuById($id){
        $good_goodsku = GoodsSku::getGoodsAndGoodsSkuById($id);
//        var_dump($good_goodsku->goods->toArray());
        if(!$good_goodsku) return false;
        return $good_goodsku;
    }

    public static function getSkuSpeciValue($goods_sku_info_speci_value){
        $ids = array_values($goods_sku_info_speci_value);
        $ids_arr = array_unique(explode(',',  implode(',', $ids) ));
        $res = GoodsServe::getSpecsValuesByIds($ids_arr);
        if(!$res) return [];

        $result = [];
        foreach ($goods_sku_info_speci_value as $k=>$v){
            $tmp = explode(',', $v);
            $sku_tmp = [];
             foreach ($tmp as $vv)  {

                 $sku_tmp[] = $res[$vv]['name'];
             }
             $result[$k] = implode("  ",$sku_tmp);
        }
        return $result;
    }

    public static function updateNum($datas){
        $res =  GoodsSku::updateNum($datas);
        return $res ;
    }

}